import 'package:boss/provider/offers_provider.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/offersManagement/page/plusOffersMode/page/fullOffers/provider/full_offers_provider.dart';
import 'package:boss/ui/page/offersManagement/page/plusOffersMode/page/widget/offers_form_field_common.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'full_offers_rule_list.dart';
import 'full_offers_title.dart';

class FullOffersBrowser extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: SingleChildScrollView(
            padding: EdgeInsets.symmetric(
              vertical: 30.w,
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                OffersFormFieldCommon<FullOffersProvider>(
                  title: '满减优惠',
                ),
                CustomDivider(
                  height: 20.w,
                ),
                FullOffersTitle(),
                FullOffersRuleList(),
                Container(
                  padding: EdgeInsets.symmetric(
                      horizontal: 55.w,
                      vertical: 38.w),
                  alignment: Alignment.centerRight,
                  child: LabelButton(
                    title: '+新增',
                    textStyle: TextStyleConstant().blue_28,
                    onTap: () {
                      var fullOffersProvider = Provider.of<FullOffersProvider>(
                        context,
                        listen: false,
                      );
                      fullOffersProvider.addRule();
                    },
                  ),
                ),
              ],
            ),
          ),
        ),
        FixedBottomBtn(
          title: '保 存',
          onTap: () async {
            var fullOffersProvider = Provider.of<FullOffersProvider>(context, listen: false,);
            var result = await fullOffersProvider.addFullOffers();
            if (result) {
              var offersProvider = Provider.of<OffersProvider>(
                context,
                listen: false,
              );
              offersProvider.backstageRefresh();
              Navigator.pop(context);
            }
          },
        ),
      ],
    );
  }
}
